package com.howcan.widget;

import android.content.Context;
import android.text.InputFilter;
import android.util.AttributeSet;
import android.widget.EditText;

public class HcEditText extends EditText
{

	int maxLength;

	public HcEditText(Context context)
	{
		super(context);
	}

	public HcEditText(Context context, AttributeSet attributeset)
	{
		super(context, attributeset);
	}

	public HcEditText(Context context, AttributeSet attributeset, int i)
	{
		super(context, attributeset, i);
	}

	public void setMaxLength(int i)
	{
		maxLength = i;
		if (i > 0)
		{
			InputFilter ainputfilter[] = new InputFilter[1];
			ainputfilter[0] = new android.text.InputFilter.LengthFilter(i);
			setFilters(ainputfilter);
		}
	}

	public void setText(CharSequence charsequence, android.widget.TextView.BufferType buffertype)
	{
		super.setText(charsequence, buffertype);
		if (charsequence == null)
			charsequence = "";
		int i;
		if (maxLength > 0 && maxLength < charsequence.length())
			i = maxLength;
		else
			i = charsequence.length();
		setSelection(i);
	}
}
